package com.xiaoran.robot.customHandler;

import com.alibaba.fastjson.JSONObject;
import com.xiaoran.robot.entity.SenderInfo;
import com.xiaoran.robot.utils.MessageParser;
import com.xiaoran.robot.utils.RstMsgUtils;
import com.xiaoran.robot.utils.ThreadLocalUtils;
import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.ArrayList;

public class Abuse {
    public ArrayList<Object> result() {
        JSONObject msg = new ThreadLocalUtils().getMsg();
        MessageParser instance = new MessageParser(msg);
        SenderInfo senderInfo = instance.senderInfo();
        String qq = senderInfo.getQid();
        RstMsgUtils rstMsg = new RstMsgUtils();
        if(senderInfo.getType().equals("GroupMessage")){
            rstMsg.atQQ(qq).addText("\n");
        }
        return rstMsg
                .addText(getAbuse()).build();
    }

    private String getAbuse(){
        String text = "";
        try {
           text = Jsoup.connect("https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn").ignoreContentType(true)
                    .get().body().text();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return text;
    }
}
